//
//  TeacherDetailTableHeaderView.m
//  huashiedu
//
//  Created by oceans on 2018/9/3.
//  Copyright © 2018年 hema. All rights reserved.
//

#import "TeacherDetailTableHeaderView.h"

@interface TeacherDetailTableHeaderView ()
@property (strong, nonatomic) CALayer *lineLayer;
@property (strong, nonatomic) UIButton *leftButton;
@property (strong, nonatomic) UIButton *rightButton;
@end

@implementation TeacherDetailTableHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        UIButton *left = [UIButton buttonWithType:UIButtonTypeCustom];
        left.backgroundColor = [UIColor whiteColor];
        left.frame = CGRectMake(0, 0, ScreenWidth * 0.5, 42);
        [left setTitleColor:[UIColor colorWithRed:63/255.0 green:63/255.0 blue:63/255.0 alpha:1.0] forState:UIControlStateNormal];
        [left setTitleColor:[UIColor colorWithRed:1.0 green:36/255.0 blue:69/255.0 alpha:1.0] forState:UIControlStateSelected];
        [left setTitle:@"资质证件" forState:UIControlStateNormal];
        left.titleLabel.font = [UIFont systemFontOfSize:15.0];
        [left addTarget:self action:@selector(buttonsPressed:) forControlEvents:UIControlEventTouchUpInside];
        self.leftButton = left;
        [self addSubview:left];
        
        UIButton *right = [UIButton buttonWithType:UIButtonTypeCustom];
        right.backgroundColor = [UIColor whiteColor];
        right.frame = CGRectMake(ScreenWidth * 0.5, 0, ScreenWidth * 0.5, 42);
        [right setTitleColor:[UIColor colorWithRed:63/255.0 green:63/255.0 blue:63/255.0 alpha:1.0] forState:UIControlStateNormal];
        [right setTitleColor:[UIColor colorWithRed:1.0 green:36/255.0 blue:69/255.0 alpha:1.0] forState:UIControlStateSelected];
        [right setTitle:@"精品课程" forState:UIControlStateNormal];
        right.titleLabel.font = [UIFont systemFontOfSize:15.0];
        right.tag = 1;
        [right addTarget:self action:@selector(buttonsPressed:) forControlEvents:UIControlEventTouchUpInside];
        self.rightButton = right;
        [self addSubview:right];
        
        self.lineLayer = [[CALayer alloc] init];
        _lineLayer.frame = CGRectMake(0, 0, 15, 4);
        _lineLayer.cornerRadius = 2.0;
        _lineLayer.masksToBounds = YES;
        _lineLayer.backgroundColor = [UIColor colorWithRed:1.0 green:36/255.0 blue:69/255.0 alpha:1.0].CGColor;
        _lineLayer.position = CGPointMake(ScreenWidth * 0.25, 38);
        [self.layer addSublayer:_lineLayer];
        
        CALayer *line = [[CALayer alloc] init];
        line.frame = CGRectMake(0, 41.5, ScreenWidth, 0.5);
        line.backgroundColor = [UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1.0].CGColor;
        [self.layer addSublayer:line];
    }
    
    return self;
}

- (void)buttonsPressed:(UIButton*)sender {
    [_delegate tableHeaderButtonsPressed:sender];
    if (sender.tag == 0) {
        _lineLayer.position = CGPointMake(ScreenWidth * 0.25, 38);
        _leftButton.selected = YES;
        _rightButton.selected = NO;
    }else {
        _lineLayer.position = CGPointMake(ScreenWidth * 0.75, 38);
        _leftButton.selected = NO;
        _rightButton.selected = YES;
    }
}

@end
